package com.itbaizhan.shopping_cartgoods_customer_api.controller;

import com.itbaizhan.shopping_common.pojo.CartGoods;
import com.itbaizhan.shopping_common.result.BaseResult;
import com.itbaizhan.shopping_common.service.CartGoodsService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/cart")
public class CartGoodsController {
    @DubboReference
    private CartGoodsService cartGoodsService;

    @GetMapping("/findCartList")
    public BaseResult findCartList(@RequestHeader Long userId){
        List<CartGoods> cartGoodsList = cartGoodsService.findAll(userId);
        return BaseResult.ok(cartGoodsList);
    }

    @PostMapping("/addCart")
    public BaseResult addCart(@RequestHeader Long userId, @RequestBody CartGoods cartGoods) {
        cartGoodsService.addCartGoods(userId,cartGoods);
        return BaseResult.ok();
    }

    @GetMapping("/handleCart")
    public BaseResult handleCart(@RequestHeader Long userId, Long goodId, Integer num) {
        cartGoodsService.updateCartGoodsNum(userId,goodId,num);
        return BaseResult.ok();
    }

    @DeleteMapping("/deleteCart")
    public BaseResult deleteCart(@RequestHeader Long userId, Long goodId) {
        cartGoodsService.deleteCartGoods(userId,goodId);
        return BaseResult.ok();
    }

}
